import requests from './request'

//获取token 提交用户名密码
export const getLoginToken = (data) => {
  return requests({ url: 'login', method: 'post', data })
}
// 获取左侧菜单数据
export const getLeftMenu = () => {
  return requests({ url: 'menus', method: 'get' })
}

// 获取用户数据
export const getUserInfo = (data) => {
  return requests({ url: 'users', method: 'get', params: data })
}

//修改用户状态
export const changeUserStatus = (uid, type) => {
  return requests({ url: `users/${uid}/state/${type}`, method: 'put' })
}

//添加用户
export const addUserList = (data) => {
  return requests({ url: 'users', method: 'post', data: data })
}

//根据id查询用户信息
export const getUserInfobyId = (id) => {
  return requests({ url: `users/${id}`, method: 'get' })
}

//根据用户id修改用户信息
export const UpdateUserInfo = (data, id) => {
  return requests({ url: `users/${id}`, method: 'put', data: data })
}

//根据id 删除用户
export const deleteUserInfo = (id) => {
  return requests({ url: `users/${id}`, method: 'delete' })
}

//获取所有权限列表
export const getRightsList = () => {
  return requests({ url: 'rights/list', method: 'get' })
}

//查询全部角色列表
export const getAllRolesList = () => {
  return requests({ url: 'roles', method: 'get' })
}

//删除角色指定权限
export const deleteRoleRight = (roleId, rightId) => {
  return requests({ url: `roles/${roleId}/rights/${rightId}`, method: 'delete' })
}

//获取所有权限列表 树状
export const getRightsTreeList = () => {
  return requests({ url: 'rights/tree', method: 'get' })
}

//为指定角色授权
export const setRoleRights = (roleid, rids) => {
  return requests({ url: `roles/${roleid}/rights`, method: 'post', data: { rids: rids } })
}

//分配用户角色
export const setUsersRole = (userid, rid) => {
  return requests({ url: `users/${userid}/role`, method: 'put', data: { rid: rid } })
}

//获取商品分类数据列表
export const getCategoriesList = (params) => {
  return requests({ url: 'categories', method: 'get', params: { type: params.type, pagenum: params.pagenum, pagesize: params.pagesize } })
}

//*添加分类
export const addcategoryInfo = (data) => {
  return requests({ url: 'categories', method: 'post', data: data })
}

//*参数列表{
export const getcategoryListbyId = (id, sel) => {
  return requests({ url: `categories/${id}/attributes`, method: 'get', params: { sel: sel } })
}

//*添加动态参数或者静态属性
export const addOnlyOrManyInfo = (id, data) => {
  return requests({
    url: `categories/${id}/attributes`,
    method: 'post',
    data: {
      attr_name: data.attr_name,
      attr_sel: data.attr_sel,
    },
  })
}

//*根据id查询参数，更新时数据回显
export const getOldOnlyOrManyInfo = (id, attrid, data) => {
  return requests({ url: `categories/${id}/attributes/${attrid}`, method: 'get', params: { attr_sel: data.attr_sel } })
}

//*更新分类参数
export const editcategoryInfo = (id, attrid, data) => {
  return requests({ url: `categories/${id}/attributes/${attrid}`, method: 'put', data: { attr_name: data.attr_name, attr_sel: data.attr_sel } })
}

//*删除参数
export const deletecategoryInfobyId = (id, attrid) => {
  return requests({ url: `categories/${id}/attributes/${attrid}`, method: 'delete' })
}

//*编辑提交参数
export const editcategorybyidattrid = (id, attrid, data) => {
  return requests({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'put',
    data: {
      attr_name: data.attr_name,
      attr_sel: data.attr_sel,
      attr_vals:data.attr_vals
    },
  })
}

//*获取商品列表数据
export const getGoodsList = (params) => { return requests({ url: 'goods', method: 'get', params: params }) }

//*根据id删除商品
export const deleteGoodByid = (id) => { return requests({ url: `goods/${id}`, method: 'delete' }) }

//*添加商品
export const addGoods = (data) => { return requests({ url: 'goods', method: 'post', data: data }) }
//*订单列表
export const getOrderList = (data) => { return requests({ url: 'orders', method: 'get', params: data }) }

//* 查看物流信息
export const getwuliu = () => { return requests({ url: '/kuaidi/1106975712662', method: 'get' }) }

//* 数据统计，获取时间统计的折线图
export const getreports = () => {
  return requests({url:'reports/type/1',method:'get'})
}